/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.edu.situacao;

import br.edu.banco.Banco;
import br.edu.util.GenericDAO;
import br.edu.util.HibernateUtil;
import java.util.List;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author 'Pedro
 */
public class SituacaoDAO extends GenericDAO<Situacao>{
    
    public SituacaoDAO(){
        super(Situacao.class);
    }

    public boolean salvar(Situacao situacao) {
        if(situacao.getId()==0){
            adicionar(situacao);
        } else {
            atualizar(situacao);
        }
        return true;
    }

    public List<Situacao> pesquisarDescricaoLike(String text) {
        List<Situacao> situacoes=null;
        setSessao(HibernateUtil.getSessionFactory().openSession());
        setTransacao(getSessao().beginTransaction());
        situacoes = (List<Situacao>) getSessao().createCriteria(Situacao.class).add(Restrictions.ilike("descricao", text)).list();
        getSessao().close();
        return situacoes;
    }

    public Situacao pesquisarCodigo(Integer valueOf) {
        Situacao situacao;
        setSessao(HibernateUtil.getSessionFactory().openSession());
        setTransacao(getSessao().beginTransaction());
        situacao = (Situacao) getSessao().createCriteria(Situacao.class).add(Restrictions.eq("id", valueOf)).uniqueResult();
        getSessao().close();
        return situacao;
    }
}
